package com.sheng.center.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.sheng.center.entity.Lab;

public class LabDaoImpl implements LabDao {
	private SessionFactory sessionFactory;
	@Override
	public void add(Lab lab) {
			lab.setIsDelete(0);
			sessionFactory.getCurrentSession().save(lab);
	}

	@Override
	public void edit(Lab lab) {
			lab.setIsDelete(0);
			sessionFactory.getCurrentSession().update(lab);
	}

	@Override
	public void delete(Lab lab) {
		lab.setIsDelete(1);
		sessionFactory.getCurrentSession().update(lab);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Lab> findAllList(Lab model) {
		String hql = "from Lab where 1=1  and is_delete=0";
		if(null != model.getLabName()){
			hql = hql + " and lab_name like '%"+model.getLabName()+"%'";
		}
		Query query = sessionFactory.getCurrentSession().createQuery(hql);  
        List list = query.list();  
        return list;
	}
	public Lab findById(Lab lab) {
		Query query = sessionFactory.getCurrentSession().createQuery("from Lab where id='"+lab.getId()+"'");  
		List list = query.list();  
		if (null != list && 0 < list.size()) {
			lab = (Lab) list.get(0);
		}
		return lab;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}


}
